<?php

namespace App\Http\Controllers\Admin;
use App\DTOS\Admin\GamePackageDTO;
use App\DTOS\Admin\GameVersionDTO;
use App\Http\Controllers\Controller;
use App\Services\Game\GamePackageService;
use App\Services\VersionEventService;
use App\Utils\MyLog;
use App\Utils\ResponseUtil;

// 包列表管理
class GamePackageController extends Controller
{
    private GamePackageService $GamePackageService;

    private VersionEventService $versionEventService;

    /**
     * GamePackageController constructor.
     * @param GamePackageService $GamePackageService
     */
    public function __construct(GamePackageService $GamePackageService,VersionEventService $versionEventService)
    {
        $this->GamePackageService = $GamePackageService;
        $this->versionEventService = $versionEventService;
    }

    public function paginate()
    {
        $paginate = $this->GamePackageService->paginate(new GamePackageDTO(request()->all()));

        $res = [];
        $res['code'] = 0;
        $res['msg'] = 'success';
        $res['data'] = $paginate->items();
        $res['count'] = $paginate->total();
        return ResponseUtil::json($res);
    }

    public function add()
    {
        try {
            $data = request()->all();
            $this->GamePackageService->add($data);
           // $this->versionEventService->refreshPackageNos();
            return ResponseUtil::success();
        }catch (\Exception $e){
            return ResponseUtil::error($e->getMessage());
        }
    }
    public function edit($id)
    {
        $data = request()->all();
        MyLog::info('包信息提交新'.json_encode($data));
        $this->GamePackageService->edit($id,$data);
       // $this->versionEventService->refreshPackageNos();
        return ResponseUtil::success();
    }
    public function detail($id)
    {
        $detail = $this->GamePackageService->detail($id);
        return ResponseUtil::success($detail);
    }
    public function delete($id)
    {
        $this->GamePackageService->delete($id);
     //   $this->versionEventService->refreshPackageNos();
        return ResponseUtil::success();
    }


    public function paginatev()
    {
        $paginate = $this->GamePackageService->paginatev(new GamePackageDTO(request()->all()));

        $res = [];
        $res['code'] = 0;
        $res['msg'] = 'success';
        $res['data'] = $paginate->items();
        $res['count'] = $paginate->total();
        return ResponseUtil::json($res);
    }

    public function addv()
    {
        try {
            $data = request()->all();
            $this->GamePackageService->addv($data);
            // $this->versionEventService->refreshPackageNos();
            return ResponseUtil::success();
        }catch (\Exception $e){
            return ResponseUtil::error($e->getMessage());
        }
    }
    public function editv($id)
    {
        $data = request()->all();
        $this->GamePackageService->editv($id,$data);
        // $this->versionEventService->refreshPackageNos();
        return ResponseUtil::success();
    }
    public function detailv($id)
    {
        $detail = $this->GamePackageService->detailv($id);
        return ResponseUtil::success($detail);
    }
    public function deletev($id)
    {
        $this->GamePackageService->deletev($id);
        //   $this->versionEventService->refreshPackageNos();
        return ResponseUtil::success();
    }

}
